package com.card.admin.pojo;

import java.util.Date;
import java.util.Random;

import com.xiaoao.net.db.Entity;
import com.xiaoao.net.db.mongo.MongodbManager;
import com.xiaoao.net.utils.TimeUtils;

/**   
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author siyunlong  
 * @date 2016年12月9日 下午4:34:07 
 * @version V1.0   
 */
public class SuperPlayer {
	public static final String T_Table = "SuperPlayer";
	public static final String Name = "Name";
	public static final String Pro = "Pro";
	public static final String Date = "date";
	private String id;
	private String name;
	private String date;
	private double pro;
	
	public SuperPlayer(String id, String name, float pro) {
		this.id = id;
		this.name = name;
		this.date = TimeUtils.ToDesString(new Date());
		this.pro = pro;
	}

	public SuperPlayer(Entity entity) {
		this.id = entity.getKey().getName();
		this.name = (String)entity.getProperty(Name);
		this.date = (String)entity.getProperty(Date);
		this.pro = (double)entity.getProperty(Pro);
	}

	public String getId() {
		return id;
	}
	public String getDate() {
		return date;
	}

	public String getName() {
		return name;
	}

	public double getPro() {
		return pro;
	}

	public boolean isFit() {
		return new Random().nextFloat() <= pro;
	}

	public void setPro(double pro) {
		this.pro = pro;
	}
	
	public void store() {
		Entity entity = new Entity(T_Table, id);
		entity.setProperty(Name, name);
		entity.setProperty(Date, date);
		entity.setProperty(Pro, pro);
		MongodbManager.getInstance().saveOrUpdate(entity);
	}
}
